home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / tests / source.test < prev    next >
Encoding:
Text File  |  1994-12-17  |  2.3 KB  |  82 lines

  1. # Commands covered:  source
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) source.test 1.9 94/12/17 16:20:24
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test source-1.1 {source command} {
  18.     set x "old x value"
  19.     set y "old y value"
  20.     set z "old z value"
  21.     exec cat << {
  22.     set x 22
  23.     set y 33
  24.     set z 44
  25.     } > source.file
  26.     source source.file
  27.     list $x $y $z
  28. } {22 33 44}
  29. test source-1.2 {source command} {
  30.     exec cat << {list result} > source.file
  31.     source source.file
  32. } result
  33.  
  34. test source-2.1 {source error conditions} {
  35.     list [catch {source} msg] $msg
  36. } {1 {wrong # args: should be "source fileName"}}
  37. test source-2.2 {source error conditions} {
  38.     list [catch {source a b} msg] $msg
  39. } {1 {wrong # args: should be "source fileName"}}
  40. test source-2.3 {source error conditions} {
  41.     exec cat << {
  42.     set x 146
  43.     error "error in sourced file"
  44.     set y $x
  45.     } > source.file
  46.     list [catch {source source.file} msg] $msg $errorInfo
  47. } {1 {error in sourced file} {error in sourced file
  48.     while executing
  49. "error "error in sourced file""
  50.     (file "source.file" line 3)
  51.     invoked from within
  52. "source source.file"}}
  53. test source-2.4 {source error conditions} {
  54.     exec cat << {break} > source.file
  55.     catch {source source.file}
  56. } 3
  57. test source-2.5 {source error conditions} {
  58.     exec cat << {continue} > source.file
  59.     catch {source source.file}
  60. } 4
  61. test source-2.6 {source error conditions} {
  62.     string tolower [list [catch {source _non_existent_} msg] $msg $errorCode]
  63. } {1 {couldn't read file "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
  64.  
  65. test source-3.1 {return in middle of source file} {
  66.     exec cat << {
  67.     set x new-x
  68.     return allDone
  69.     set y new-y
  70.     } > source.file
  71.     set x old-x
  72.     set y old-y
  73.     set z [source source.file]
  74.     list $x $y $z
  75. } {new-x old-y allDone}
  76.  
  77. catch {exec rm source.file}
  78.  
  79. # Generate null final value
  80.  
  81. concat {}
  82.